package ncme.auto.framework.core.exceptions;

import ncme.auto.framework.core.annotation.Remind;

public enum ExceptionEnum {
    REGISTER(1104, "注册失败"),
    REDIS(1105, "缓存异常"),
    PERMISSION(1107, "没有权限"),
    REPETITION(1108, "有重复项"),
    JDBC(1109, "数据库处理失败"),
    NOT_EXIST(1110, "数据不存在"),
    UP_LOAD(1112, "上传失败"),
    ANNOTATION(1120, "实体注解、字段命名异常"),
    PARAM_FIELD(1121, "参数实体取值异常"),
    FIELD_VALUE(1122, "反射取值、赋值异常"),
    BEING_USED(1130, "数据正在使用"),
    @Remind("有此异常的需要处理数据库或实际存储中的错误数据")
    IMPORTANT(1132, "文件数据异常"),
    AUTO_SERVICE_ERROR(1133, "自动服务异常"),
    UTIL_ERROR(1134, "工具类异常"),
    PLUGIN(1140, "mybatis插件错误"),
    SERVICE_OTHER(1141, "其他服务错误"),
    LOGIN_OUT(1143, "该用户在其他设备上登录"),
    TOKEN_ERROR(1144, "token无效");


    private Integer code;
    private String msg;

    private ExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ExceptionEnum getExceptionEnum(Integer code) {
        for (ExceptionEnum value : ExceptionEnum.values()) {
            if (value.getCode().equals(code)) return value;
        }
        return SERVICE_OTHER;
    }

}
